home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / ServerModels / ColdFusion / dwscriptsServerImpl.js < prev   
Encoding:
JavaScript  |  2003-09-05  |  24.5 KB  |  918 lines

  1. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. // *************** GLOBALS VARS *****************
  4.  
  5. // ***************** LOCAL FUNCTIONS  ******************
  6.  
  7. //--------------------------------------------------------------------
  8. // FUNCTION:
  9. //   queueDefaultDocEdits
  10. //
  11. // DESCRIPTION:
  12. //   This function is called before the docEdits are applied to the
  13. //   page to allow any default doc edits to be added.
  14. //
  15. // ARGUMENTS:
  16. //   none
  17. //
  18. // RETURNS:
  19. //   nothing
  20. //--------------------------------------------------------------------
  21.  
  22. function queueDefaultDocEdits()
  23. {
  24.   var partList = null;
  25.   
  26.   partList = dw.getParticipants("PageDirective_processDir");
  27.   if (partList && partList.length)
  28.   {
  29.     dwscripts.queueParticipantInfo("PageDirective_processDir", partList[0].participantNode);
  30.   }
  31.   
  32.   partList = dw.getParticipants("PageDirective_content");
  33.   if (partList && partList.length)
  34.   {
  35.     dwscripts.queueParticipantInfo("PageDirective_content", partList[0].participantNode);
  36.   }
  37.  
  38.   partList = dw.getParticipants("PageDirective_setEncoding");
  39.   if (partList && partList.length)
  40.   {
  41.     for (var i=0; i < partList.length; i++)
  42.     {
  43.        dwscripts.queueParticipantInfo("PageDirective_setEncoding", partList[i].participantNode);
  44.     }
  45.   }
  46. }
  47.  
  48.  
  49. //--------------------------------------------------------------------
  50. // FUNCTION:
  51. //   encodeDynamicExpression
  52. //
  53. // DESCRIPTION:
  54. //   This function prepares a dynamic expression for insertion onto
  55. //   the page.  It is assumed that this expression will be used
  56. //   within a larger dynamic statement, therefore all server markup
  57. //   is stripped.
  58. //
  59. // ARGUMENTS:
  60. //   expression - string - the dyanmic expression to encode
  61. //
  62. // RETURNS:
  63. //   string
  64. //--------------------------------------------------------------------
  65.  
  66. function encodeDynamicExpression(expression)
  67. {
  68.   var retVal = "";
  69.   if (expression == null)
  70.   {
  71.     return retVal;
  72.   }
  73.   expression = expression.toString();
  74.  
  75.   if (hasServerMarkup(expression))
  76.   {
  77.     retVal = trimServerMarkup(expression, true);
  78.   }
  79.   else
  80.   {
  81.     var parameters = expression.match(/(true|false|[-]?\d+[\.]?\d*)/i);
  82.     if (parameters && parameters[0].length == expression.length) // matches, return exact
  83.     {
  84.       retVal = expression;
  85.     }
  86.     else
  87.     {
  88.       if (!dwscripts.isQuoted(expression))
  89.       {
  90.         retVal = "\"" + dwscripts.escQuotes(expression) + "\"";
  91.       }
  92.       else
  93.       {
  94.         retVal = expression;
  95.       }
  96.     }
  97.   }
  98.  
  99.   return retVal;
  100. }
  101.  
  102.  
  103. //--------------------------------------------------------------------
  104. // FUNCTION:
  105. //   decodeDynamicExpression
  106. //
  107. // DESCRIPTION:
  108. //   This function prepares a dynamic expression for display within
  109. //   a dialog box.  Quotes are removed,a nd server markup is re-added.
  110. //
  111. // ARGUMENTS:
  112. //   expression - string - the dynamic expression to prepare for display
  113. //
  114. // RETURNS:
  115. //   string
  116. //--------------------------------------------------------------------
  117.  
  118. function decodeDynamicExpression(expression)
  119. {
  120.   var retVal = "";
  121.  
  122.   expression = dwscripts.trim(expression.toString());
  123.   var unquoted = dwscripts.trimQuotes(expression);
  124.  
  125.   var parameters = unquoted.match(/(true|false|[-]?\d+[\.]?\d*)/i);
  126.   if (parameters && parameters[0].length == unquoted.length) // matches, return exact
  127.   {
  128.     retVal = expression;
  129.   }
  130.   else
  131.   {
  132.     if (dwscripts.isQuoted(expression))
  133.     {
  134.       retVal = dwscripts.unescQuotes(unquoted);
  135.     }
  136.     else if (!(   expression.charAt(0) == "#"
  137.                && expression.charAt(expression.length-1) == "#"
  138.               )
  139.             )
  140.     {
  141.       retVal = "#" + expression +"#";  // no need to add cfoutput tags
  142.     }
  143.     else
  144.     {
  145.       retVal = expression;
  146.     }
  147.   }
  148.  
  149.   return retVal;
  150. }
  151.  
  152.  
  153. //--------------------------------------------------------------------
  154. // FUNCTION:
  155. //   hasServerMarkup
  156. //
  157. // DESCRIPTION:
  158. //   This function returns true if the given expression contains
  159. //   server markup.
  160. //
  161. // ARGUMENTS:
  162. //   expression - string - the expression to test for server markup
  163. //
  164. // RETURNS:
  165. //   boolean
  166. //--------------------------------------------------------------------
  167.  
  168. function hasServerMarkup(expression)
  169. {
  170.   var retVal = false;
  171.  
  172.   expression = expression.toString();
  173.  
  174.   var exp1 = /<cfoutput[^>]*>/gi;
  175.   var exp2 = /<\/cfoutput>/gi;
  176.   if ((expression.search(exp1) != -1 && expression.search(exp2) != -1))
  177.   {
  178.     retVal = true;
  179.   }
  180.  
  181.   if (!retVal)
  182.   {
  183.     // search for the starting and closing pound signs
  184.     //  need to handle pound signs escaped with double pounds
  185.  
  186.     var beginindex = expression.indexOf("#");
  187.     while (beginindex != -1)
  188.     {
  189.       if (beginindex+1 >= expression.length || expression.charAt(beginindex+1) != "#")
  190.       {
  191.         break;
  192.       }
  193.       beginindex = expression.indexOf("#", beginindex+2);
  194.     }
  195.     if (beginindex != -1)
  196.     {
  197.       var endindex = expression.indexOf("#", beginindex+1);
  198.       while (endindex != -1)
  199.       {
  200.         if (endindex+1 >= expression.length || expression.charAt(endindex+1) != "#")
  201.         {
  202.           break;
  203.         }
  204.         endindex = expression.indexOf("#", endindex+2);
  205.       }
  206.  
  207.       if (beginindex != -1 && endindex != -1)
  208.       {
  209.         retVal = true;
  210.       }
  211.     }
  212.   }
  213.  
  214.   return retVal;
  215. }
  216.  
  217.  
  218. //--------------------------------------------------------------------
  219. // FUNCTION:
  220. //   trimServerMarkup
  221. //
  222. // DESCRIPTION:
  223. //   This function returns the given expression with any server markup
  224. //   removed.
  225. //
  226. // ARGUMENTS:
  227. //   expression - string - the expression to remove server markup from
  228. //   ignorePoundSigns - boolean - if true, the pound signs will not
  229. //     be removed from the expression
  230. //
  231. // RETURNS:
  232. //   string
  233. //--------------------------------------------------------------------
  234.  
  235. function trimServerMarkup(expression, ignorePoundSigns)
  236. {
  237.   var retVal = expression.toString();
  238.  
  239.   var exp1 = /<cfoutput[^>]*>/gi;
  240.   var exp2 = /<\/cfoutput[^>]*>/gi;
  241.  
  242.   retVal = retVal.replace(exp1,"");
  243.   retVal = retVal.replace(exp2,"");
  244.  
  245.   if (!ignorePoundSigns)
  246.   {
  247.     // search for the starting and closing pound signs
  248.     //  need to handle pound signs escaped with double pounds
  249.  
  250.     var beginindex = retVal.indexOf("#");
  251.     while (beginindex != -1)
  252.     {
  253.       if (beginindex+1 >= retVal.length || retVal.charAt(beginindex+1) != "#")
  254.       {
  255.         break;
  256.       }
  257.       beginindex = retVal.indexOf("#", beginindex+2);
  258.     }
  259.     if (beginindex != -1)
  260.     {
  261.       var endindex = retVal.indexOf("#", beginindex+1);
  262.       while (endindex != -1)
  263.       {
  264.         if (endindex+1 >= retVal.length || retVal.charAt(endindex+1) != "#")
  265.         {
  266.           break;
  267.         }
  268.         endindex = retVal.indexOf("#", endindex+2);
  269.       }
  270.       if (beginindex != -1 && endindex != -1)
  271.       {
  272.         retVal = retVal.substring(beginindex+1,endindex);
  273.       }
  274.     }
  275.   }
  276.  
  277.   retVal = dwscripts.trim(retVal);
  278.  
  279.   return retVal;
  280. }
  281.  
  282.  
  283. //--------------------------------------------------------------------
  284. // FUNCTION:
  285. //   preprocessDocEditInsertText
  286. //
  287. // DESCRIPTION:
  288. //   This function is called during dwscripts.applyDocEdits(), to
  289. //   allow the Server Models to pre-process the inserted text.
  290. //   It returns he processed string which should be inserted into
  291. //   the document.
  292. //
  293. //   For Cold Fusion, we need to strip any nested CFOUTPUT tags
  294. //
  295. // ARGUMENTS:
  296. //   insertText - string - the text that will be inserted
  297. //   editNode - DOM node - the location where this text will be inserted
  298. //   isUpdate - boolean - true if we are updating the node, rather
  299. //     than inserting for the first time.
  300. //
  301. // RETURNS:
  302. //   string - the new insert text
  303. //--------------------------------------------------------------------
  304.  
  305. function preprocessDocEditInsertText(insertText, editNode, isUpdate)
  306. {
  307.   var retVal = String(insertText);
  308.  
  309.   if (retVal)
  310.   {
  311.     var indexStartCFOutput = retVal.search(/<cfoutput/i);
  312.     if (indexStartCFOutput != -1) //if contains <cfoutput>
  313.     {
  314.       var callback = new Object();
  315.       callback.tagName = "";
  316.       callback.queryAttr = "";
  317.       callback.tagEnd = false;
  318.       callback.openTagBegin = new Function("tag,offset","if (!this.tagName) { this.tagName = tag.toUpperCase(); }");
  319.       callback.attribute = new Function("name,code","if (!this.tagEnd && !this.queryAttr && name.toUpperCase() == \"QUERY\") { this.queryAttr = code; }");
  320.       callback.openTagEnd = new Function("","this.tagEnd = true;");
  321.  
  322.       dw.scanSourceString(retVal, callback);
  323.       
  324.       // If this is a repeat region, strip the inner tags
  325.       if (callback.tagName == "CFOUTPUT" &&
  326.           callback.queryAttr != "")
  327.       {
  328.         // don't strip any cfoutputs if we are updating a repeat region
  329.         if (!isUpdate)
  330.         {
  331.           // The insertText may contain nested cfoutputs. We must remove the inner
  332.           //   cfoutputs. A scenario where this might occur is if we are wrapping
  333.           //   dynamic text with a repeat region. In this case, the insert becomes
  334.           //   a replace of the dynamic text cfoutput node with the repeat region
  335.           //   cfoutput enclosing the dynamic text cfoutput as the insert text.
  336.           var capsRetVal = retVal.toUpperCase();
  337.           var indexEndCFOutput = capsRetVal.lastIndexOf("</CFOUTPUT");
  338.           var innerSlice = retVal.substring(indexStartCFOutput + 1, indexEndCFOutput + 1);
  339.           var innerSliceSansCFOutputs = dwscripts.stripCFOutputTags(innerSlice);
  340.           retVal = retVal.substring(0, indexStartCFOutput + 1)
  341.                  + innerSliceSansCFOutputs
  342.                  + retVal.substring(indexEndCFOutput + 1);
  343.         }
  344.       }
  345.       else
  346.       {
  347.         var dom = dw.getDocumentDOM();
  348.         if (dom)
  349.         {
  350.           // If we have an edit node, turn it into offsets.
  351.           var charRange = null;
  352.           if (editNode)
  353.           {
  354.             var offsets = dom.nodeToOffsets(editNode);
  355.             charRange = {startoffset: offsets[0], endoffset: offsets[1]};
  356.           }
  357.  
  358.           if (dwscripts.canStripCfOutputTags(charRange))
  359.           {
  360.             retVal = dwscripts.stripCFOutputTags(retVal);
  361.           }
  362.         }
  363.       }
  364.     }
  365.   }
  366.  
  367.   return retVal;
  368. }
  369.  
  370.  
  371. //--------------------------------------------------------------------
  372. // FUNCTION:
  373. //   getDBColumnTypeAsString
  374. //
  375. // DESCRIPTION:
  376. //   Maps the enumerated number used by the database to represent a type to the
  377. //   corresponding sql type string.
  378. //
  379. // ARGUMENTS:
  380. //   typeNum - enumerated number. Number used by the database to represent
  381. //     the type.
  382. //
  383. // RETURNS:
  384. //   string - ColdFusion SQL type string. null if typeNum is not found.
  385. //--------------------------------------------------------------------
  386.  
  387. function getDBColumnTypeAsString(typeNum)
  388. {
  389. // todo: should store dbtype array somewhere like in dwscripts?
  390.   var retVal = null;
  391.   var a = new Array();
  392.  
  393.   a[0] = "Empty";
  394.   a[2] = "CF_SQL_SMALLINT";
  395.   a[3] = "CF_SQL_INTEGER";
  396.   a[4] = "CF_SQL_FLOAT";
  397.   a[5] = "CF_SQL_FLOAT";
  398.   a[6] = "CF_SQL_MONEY";
  399.   a[7] = "CF_SQL_DATE";
  400.   a[8] = "CF_SQL_CHAR"; //?
  401.   a[9] = "IDispatch";
  402.   a[10] = "Error";
  403.   a[11] = "CF_SQL_BIT"; //Boolean
  404.   a[12] = "Variant";
  405.   a[13] = "IUnknown";
  406.   a[14] = "CF_SQL_DECIMAL"; //Decimal
  407.   a[16] = "CF_SQL_TINYINT"; //TinyInt
  408.   a[17] = "CF_SQL_TINYINT"; //UnsignedTinyInt
  409.   a[18] = "CF_SQL_SMALLINT"; //UnsignedSmallInt
  410.   a[19] = "CF_SQL_INTEGER"; //UnsignedInt
  411.   a[20] = "CF_SQL_BIGINT"; //BigInt
  412.   a[21] = "CF_SQL_BIGINT"; //UnsignedBigInt
  413.   a[72] = "GUID";
  414.   a[128] = "Binary";
  415.   a[129] = "CF_SQL_CHAR"; //Char
  416.   a[130] = "CF_SQL_CHAR"; //WChar
  417.   a[131] = "CF_SQL_NUMERIC"; //Numeric
  418.   a[132] = "UserDefined";
  419.   a[133] = "CF_SQL_DATE"; //DBDate
  420.   a[134] = "CF_SQL_TIME"; //DBTime
  421.   a[135] = "CF_SQL_TIMESTAMP"; //DBTimeStamp
  422.   a[200] = "CF_SQL_VARCHAR"; //VarChar
  423.   a[201] = "CF_SQL_LONGVARCHAR"; //LongVarChar
  424.   a[202] = "CF_SQL_VARCHAR"; //VarWChar
  425.   a[203] = "CF_SQL_LONGVARCHAR"; //LongVarWChar
  426.   a[204] = "VarBinary";
  427.   a[205] = "LongVarBinary";
  428.   //Defined for CF support
  429.   a[400] = "CF_SQL_REAL";
  430.   a[401] = "CF_SQL_FLOAT";
  431.   a[402] = "CF_SQL_LONGVARCHAR";
  432.   a[403] = "CF_SQL_MONEY4";
  433.   a[900] = "REF CURSOR" // Special case for Oracle
  434.   a[901] = "CF_SQL_BIT";
  435.  
  436.   if (a[typeNum])
  437.   {
  438.     retVal = a[typeNum];
  439.   }
  440.  
  441.   return retVal;
  442. }
  443.  
  444.  
  445. //--------------------------------------------------------------------
  446. // FUNCTION:
  447. //   getColumnValueNode
  448. //
  449. // DESCRIPTION:
  450. //   This function returns a platform specific instance of the
  451. //   ColumnValueNode class.  This function is called by dwscripts,
  452. //   and serves as a factory method.
  453. //
  454. // ARGUMENTS:
  455. //   none
  456. //
  457. // RETURNS:
  458. //   CFColumnValueNode object
  459. //--------------------------------------------------------------------
  460.  
  461. function getColumnValueNode()
  462. {
  463.   var retVal = new CFColumnValueNode();
  464.   return retVal;
  465. }
  466.  
  467.  
  468.  
  469.  
  470.  
  471. //--------------------------------------------------------------------
  472. // CLASS:
  473. //   CFColumnValueNode
  474. //
  475. // DESCRIPTION:
  476. //   This class represents the mapping of a database column to a value.
  477. //
  478. // PUBLIC PROPERTIES:
  479. //   None
  480. //
  481. // PUBLIC FUNCTIONS:
  482. //   See the base class in:
  483. //     Configuration/Shared/Common/Scripts/ColumnValueNodeClass.js
  484. //
  485. //--------------------------------------------------------------------
  486.  
  487. //--------------------------------------------------------------------
  488. // FUNCTION:
  489. //   CFColumnValueNode
  490. //
  491. // DESCRIPTION:
  492. //   Consructor function for the ColdFusion specific ColumnValueNode class
  493. //
  494. // ARGUMENTS:
  495. //   none
  496. //
  497. // RETURNS:
  498. //   nothing
  499. //--------------------------------------------------------------------
  500.  
  501. function CFColumnValueNode()
  502. {
  503.   this.initialize();
  504. }
  505.  
  506. // Inherit from the ColumnValueNode class.
  507. CFColumnValueNode.prototype.__proto__ = ColumnValueNode.prototype;
  508.  
  509. CFColumnValueNode.prototype.encodeSQLVarRef = CFColumnValueNode_encodeSQLVarRef;
  510. CFColumnValueNode.prototype.decodeSQLVarRef = CFColumnValueNode_decodeSQLVarRef;
  511.  
  512. CFColumnValueNode.prototype.getRuntimeValue = CFColumnValueNode_getRuntimeValue;
  513. CFColumnValueNode.prototype.setRuntimeValue = CFColumnValueNode_setRuntimeValue;
  514.  
  515.  
  516. //--------------------------------------------------------------------
  517. // FUNCTION:
  518. //   CFColumnValueNode.encodeSQLVarRef
  519. //
  520. // DESCRIPTION:
  521. //   Given a variable name and a wrap character, returns a string
  522. //   suitable for insertion into a SQL statement
  523. //
  524. // ARGUMENTS:
  525. //   variable - string - the variable reference to encode
  526. //   wrapChar - string - the character to enclose the reference in
  527. //
  528. // RETURNS:
  529. //   string
  530. //--------------------------------------------------------------------
  531.  
  532. function CFColumnValueNode_encodeSQLVarRef(variable, wrapChar)
  533. {
  534.   var sqlVarRef = "#" + variable + "#";
  535.  
  536.   if (wrapChar)
  537.   {
  538.     // Must escape a wrapchar of '#'
  539.     if (wrapChar == "#")
  540.     {
  541.       wrapChar = "##";
  542.     }
  543.     sqlVarRef = wrapChar + sqlVarRef + wrapChar;
  544.   }
  545.  
  546.   return sqlVarRef;
  547. }
  548.  
  549.  
  550. //--------------------------------------------------------------------
  551. // FUNCTION:
  552. //   CFColumnValueNode.decodeSQLVarRef
  553. //
  554. // DESCRIPTION:
  555. //   Given a SQL variable reference, this function extracts the
  556. //   variable name and the wrap character.
  557. //
  558. // ARGUMENTS:
  559. //   sqlVarRef - string - the SQL variable reference to decode
  560. //
  561. // RETURNS:
  562. //   object with two properties: variable and wrapChar
  563. //--------------------------------------------------------------------
  564.  
  565. function CFColumnValueNode_decodeSQLVarRef(sqlVarRef)
  566. {
  567.   var retVal = new Object();
  568.   retVal.value = sqlVarRef;
  569.   retVal.variable = "";
  570.   retVal.wrapChar = "";
  571.  
  572.   if (sqlVarRef.charAt(0) == sqlVarRef.charAt(sqlVarRef.length-1))
  573.   {
  574.     if (sqlVarRef.indexOf("###") == -1)
  575.     {
  576.       if (sqlVarRef.charAt(0) != "#")
  577.       {
  578.         retVal.wrapChar = sqlVarRef.charAt(0);
  579.         retVal.variable = sqlVarRef.substring(1,sqlVarRef.length-1);
  580.         if (retVal.variable.charAt(0) == retVal.variable.charAt(retVal.variable.length-1) &&
  581.             retVal.variable.charAt(0) == "#")
  582.         {
  583.           retVal.variable = retVal.variable.substring(1,retVal.variable.length-1);
  584.         }
  585.         else
  586.         {
  587.           // this is not a variable
  588.           retVal.variable = "";
  589.           retVal.wrapChar = "";
  590.         }
  591.       }
  592.       else
  593.       {
  594.         retVal.variable = sqlVarRef.substring(1,sqlVarRef.length-1);
  595.       }
  596.     }
  597.     else
  598.     {
  599.       // this is an access date, handle differently
  600.       retVal.wrapChar = "#";
  601.       retVal.variable = sqlVarRef.substring(3,sqlVarRef.length-3);
  602.     }
  603.   }
  604.  
  605.   return retVal;
  606. }
  607.  
  608.  
  609. //--------------------------------------------------------------------
  610. // FUNCTION:
  611. //   CFColumnValueNode.getRuntimeValue
  612. //
  613. // DESCRIPTION:
  614. //   Returns the runtime value suitable for insertion into a SQL
  615. //   statement, for this column value mapping.
  616. //
  617. //   NOTE: This is an override of a base class method
  618. //
  619. // ARGUMENTS:
  620. //   none
  621. //
  622. // RETURNS:
  623. //   string
  624. //--------------------------------------------------------------------
  625.  
  626. function CFColumnValueNode_getRuntimeValue()
  627. {
  628.   this.runtimeValue = "";
  629.  
  630.   if (this.varName)
  631.   {
  632.     this.runtimeValue = this.encodeSQLVarRef(this.varName, this.wrapChar);
  633.  
  634.     if (!this.isPrimaryKey)
  635.     {
  636.       if (this.altValue && this.defaultValue)
  637.       {
  638.         // generate the value for this column
  639.         var paramObj = new Object();
  640.         paramObj.Variable = this.varName;
  641.         paramObj.AltValue = this.altValue;
  642.         paramObj.DefaultValue = this.defaultValue;
  643.  
  644.         this.runtimeValue = extPart.getInsertString("", "SQLVariable_altValue", paramObj);
  645.       }
  646.       else if (this.defaultValue)
  647.       {
  648.         // generate the value for this column
  649.         var paramObj = new Object();
  650.         paramObj.Variable = this.varName;
  651.         paramObj.RuntimeValue = this.runtimeValue;
  652.         paramObj.DefaultValue = this.defaultValue;
  653.  
  654.         this.runtimeValue = extPart.getInsertString("", "SQLVariable_defaultValue", paramObj);
  655.       }
  656.     }
  657.   }
  658.  
  659.   return this.runtimeValue;
  660. }
  661.  
  662.  
  663. //--------------------------------------------------------------------
  664. // FUNCTION:
  665. //   CFColumnValueNode.setRuntimeValue
  666. //
  667. // DESCRIPTION:
  668. //   Given a runtime value from a SQL statement, this function sets
  669. //   the properties of this object to match this runtime code.
  670. //
  671. //   NOTE: This is an override of a base class function
  672. //
  673. // ARGUMENTS:
  674. //   runtimeValue - string - a SQL column value mapping
  675. //
  676. // RETURNS:
  677. //   nothing
  678. //--------------------------------------------------------------------
  679.  
  680. function CFColumnValueNode_setRuntimeValue(runtimeValue)
  681. {
  682.   this.runtimeValue = runtimeValue;
  683.  
  684.   // check if we have an altValue or defaultValue string
  685.   var paramObj = extPart.findInString("SQLVariable_altValue", this.runtimeValue);
  686.   if (paramObj != null)
  687.   {
  688.     // we have an alt value
  689.     this.varName = paramObj["Variable"];
  690.     this.wrapChar = "";
  691.     this.altValue = paramObj["AltValue"];
  692.     this.defaultValue = paramObj["DefaultValue"];
  693.   }
  694.   else
  695.   {
  696.     paramObj = extPart.findInString("SQLVariable_defaultValue", this.runtimeValue);
  697.     if (paramObj != null)
  698.     {
  699.       // we have a default value
  700.       this.varName = paramObj["Variable"];
  701.       this.wrapChar = this.decodeSQLVarRef(paramObj["RuntimeValue"]).wrapChar;
  702.       this.altValue = "";
  703.       this.defaultValue = paramObj["DefaultValue"];
  704.     }
  705.     else
  706.     {
  707.       // we have a normal value
  708.       var info = this.decodeSQLVarRef(this.runtimeValue);
  709.       this.varName = info.variable;
  710.       this.wrapChar = info.wrapChar;
  711.       this.altValue = "";
  712.       this.defaultValue = "NULL";
  713.     }
  714.   }
  715. }
  716.  
  717.  
  718. //--------------------------------------------------------------------
  719. // FUNCTION:
  720. //   getParameterTypeArray
  721. //
  722. // DESCRIPTION:
  723. //   Get list of available parameter types.
  724. //
  725. // ARGUMENTS:
  726. //   bRemoveEnteredVal - boolean (optional). 'true' if should remove 'Entered Value'
  727. //     as a possible parameter type. Defaults to 'false'.
  728. //
  729. // RETURNS:
  730. //   array of strings - localized list of parameter types.
  731. //--------------------------------------------------------------------
  732.  
  733. function getParameterTypeArray(bRemoveEnteredVal)
  734. {
  735.   // Make a copy of MM.LABEL_CF_Param_Types. We may need to alter it and we
  736.   //   don't want to affect the original array.
  737.   var paramTypes = new Array();
  738.   for (var i = 0; i < MM.LABEL_CF_Param_Types.length; ++i)
  739.   {
  740.     paramTypes.push(MM.LABEL_CF_Param_Types[i]);
  741.   }
  742.  
  743.   if (bRemoveEnteredVal)
  744.   {
  745.     paramTypes.splice(paramTypes.length - 1, 1);
  746.   }
  747.  
  748.   return paramTypes;
  749. }
  750.  
  751.  
  752. //--------------------------------------------------------------------
  753. // FUNCTION:
  754. //   getParameterCodeFromType
  755. //
  756. // DESCRIPTION:
  757. //   Gets the runtime code and default value for the parameter type.
  758. //
  759. // ARGUMENTS:
  760. //   paramType - string. one of elements returned from getParameterTypeArray.
  761. //   paramNameOrValue - string. Value for the parameter.
  762. //
  763. // RETURNS:
  764. //   object - with runtimeVal, defaultVal, and nameVal properties. null
  765. //     if no parameter is used.
  766. //--------------------------------------------------------------------
  767.  
  768. function getParameterCodeFromType(paramType, paramNameOrValue, paramDefault)
  769. {
  770.   var runtimeVal = dwscripts.sprintf(MM.MSG_UnknownParamType, paramType);
  771.   var nameVal = "";
  772.   var defaultVal = "1";
  773.  
  774.   switch(paramType)
  775.   {
  776.     case MM.LABEL_CF_Param_Types[0]:
  777.       runtimeVal = "#URL." + paramNameOrValue + "#";
  778.       nameVal = "URL." + paramNameOrValue;
  779.       break;
  780.     case MM.LABEL_CF_Param_Types[1]:
  781.       runtimeVal = "#FORM." + paramNameOrValue + "#";
  782.       nameVal = "FORM." + paramNameOrValue;
  783.       break;
  784.     case MM.LABEL_CF_Param_Types[2]:
  785.       runtimeVal = "#COOKIE." + paramNameOrValue + "#";
  786.       nameVal = "COOKIE." + paramNameOrValue;
  787.       break;
  788.     case MM.LABEL_CF_Param_Types[3]:
  789.       runtimeVal = "#SESSION." + paramNameOrValue + "#";
  790.       nameVal = "SESSION." + paramNameOrValue;
  791.       break;
  792.     case MM.LABEL_CF_Param_Types[4]:
  793.       runtimeVal = "#APPLICATION." + paramNameOrValue + "#";
  794.       nameVal = "APPLICATION." + paramNameOrValue;
  795.       break;
  796.   }
  797.  
  798.   var outObj = new Object();
  799.   if (paramType == MM.LABEL_CF_Param_Types[5])
  800.   {
  801.     outObj = null;
  802.   }
  803.   else
  804.   {
  805.     outObj.defaultVal = defaultVal;
  806.     outObj.runtimeVal = runtimeVal;
  807.     outObj.nameVal = nameVal;
  808.   }
  809.  
  810.   return outObj;
  811. }
  812.  
  813.  
  814. //--------------------------------------------------------------------
  815. // FUNCTION:
  816. //   getParameterTypeFromCode
  817. //
  818. // DESCRIPTION:
  819. //   Get parameter type and name from its runtime value.
  820. //
  821. // ARGUMENTS:
  822. //   runtimeValue - string - the runtime code
  823. //
  824. // RETURNS:
  825. //   object - contains paramType (one of elements returned from getParameterTypeArray)
  826. //     and paramName properties.
  827. //--------------------------------------------------------------------
  828.  
  829. function getParameterTypeFromCode(runtimeValue)
  830. {
  831.   var runtimeVal = runtimeValue;
  832.  
  833.   var outObj = new Object();
  834.  
  835.   var paramType = -1;
  836.   var paramName = runtimeValue;
  837.  
  838.   if (runtimeVal.search(/\s*url\.([^"]*)\s*/i) != -1)
  839.   {
  840.     paramType = MM.LABEL_CF_Param_Types[0];
  841.   }
  842.   else if (runtimeVal.search(/\s*form\.([^"]*)\s*/i) != -1)
  843.   {
  844.     paramType = MM.LABEL_CF_Param_Types[1];
  845.   }
  846.   else if (runtimeVal.search(/\s*cookie\.([^"]*)\s*/i) != -1)
  847.   {
  848.     paramType = MM.LABEL_CF_Param_Types[2];
  849.   }
  850.   else if (runtimeVal.search(/\s*session\.([^"]*)\s*/i) != -1)
  851.   {
  852.     paramType = MM.LABEL_CF_Param_Types[3];
  853.   }
  854.   else if (runtimeVal.search(/\s*application\.([^"]*)\s*/i) != -1)
  855.   {
  856.     paramType = MM.LABEL_CF_Param_Types[4];
  857.   }
  858.   else
  859.   {
  860.     paramType = MM.LABEL_CF_Param_Types[5];
  861.   }
  862.  
  863.   if (paramType == MM.LABEL_CF_Param_Types[5])
  864.   {
  865.     paramName = runtimeValue;
  866.   }
  867.   else
  868.   {
  869.     paramName = RegExp.$1;
  870.   }
  871.  
  872.   if (paramType != -1)
  873.   {
  874.     outObj.paramType = paramType;
  875.     outObj.paramName = paramName;
  876.     return outObj;
  877.   }
  878.   else
  879.   {
  880.     return false;
  881.   }
  882. }
  883.  
  884.  
  885. //--------------------------------------------------------------------
  886. // FUNCTION:
  887. //   isValidServerVarName
  888. //
  889. // DESCRIPTION:
  890. //   Returns true if the given variable name is legal
  891. //
  892. // ARGUMENTS:
  893. //   theVarName - string - variable to check
  894. //
  895. // RETURNS:
  896. //   boolean
  897. //--------------------------------------------------------------------
  898.  
  899. function isValidServerVarName(theVarName)
  900. {
  901.   var retVal = true;
  902.  
  903.   var parts = theVarName.split(".");
  904.  
  905.   for (var i=0; i < parts.length; i++)
  906.   {
  907.     if (!dwscripts.isValidVarName(parts[i]))
  908.     {
  909.       retVal = false;
  910.       break;
  911.     }
  912.   }
  913.  
  914.   return retVal;
  915. }
  916.  
  917.  
  918.